package com.link.base.base.orgnization.controller;


import com.link.base.base.orgnization.model.Partner;
import com.link.base.base.orgnization.service.PartnerService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/link/partner")
public class PartnerController extends BasicController<Partner> {

    @Resource
    private PartnerService partnerService;

    @Override
    public BasicService<Partner> getBasicService() throws Exception {
        return partnerService;
    }

    @RequestMapping(value = "/setDefaultPartner", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> setDefaultAddr(@JsonParam Partner record) {
        Map<String, Object> result = new HashMap<>();
        try {
            partnerService.defaultPartnerUpdate(record);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
